﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Tomahawk.Runtime.Logic.UI;
using Tomahawk.Runtime.Rendering.Materials;

namespace Tomahawk.Runtime.Logic
{
    /// <summary>
    /// Default engine configuration class
    /// </summary>
    public class XEngineConfiguration : XObject
    {

        #region "Serializable Properties"

        /// <summary>
        /// Struct used to instance game manager automatically
        /// </summary>
        public struct GameManagerReference
        {
            [XmlAttribute("type")]
            public string Type;

            [XmlAttribute("archetype")]
            public string Archetype;
        }

        [XmlElement("StyleManager")]
        public GameManagerReference _StyleManager;

        [XmlElement("SceneShader")]
        public string sceneShaderName = @"Tomahawk.Content\Materials\materials@scene_simple_Material";

        #endregion

        #region "Game Managers"

        private XStyleManager styleManager;
        
        public XStyleManager StyleManager
        {
            get { return this.styleManager; }
        }

        #endregion

        /// <summary>
        /// Utility method: Instance an object manager from a reference
        /// </summary>
        private XObject instanceManager(String name, GameManagerReference reference)
        {
            XObject returnObject = null;
            if ((reference.Type != null) && (reference.Type != ""))
            {
                Type managerType = Type.GetType(reference.Type);
                returnObject = XWorld.Instance.CreateObject(managerType, name, reference.Archetype);
            }
            return returnObject;
        }

        /// <summary>
        /// Initialization
        /// </summary>
        protected override void OnInitialize()
        {
            base.OnInitialize();

            //Instance game managers
            this.styleManager = (XStyleManager)this.instanceManager("StyleManager", this._StyleManager);
        }

    }

}
